package com.his.dictusageitem.controller;

import com.his.common.verification.group.Change;
import com.his.common.verification.group.Insert;
import com.his.config.annotation.CurrentUser;
import com.his.dictusageitem.service.DictUsageItemService;
import com.his.dictusageitem.vo.DictUsageItemVo;
import com.his.login.entity.DictEmployee;
import com.xiao.common.controller.ResultBaseController;
import com.xiao.common.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * 用法与项目关系维护
 * @Author tansonglin
 * @Date 2020/3/30
 */
@RestController
@RequestMapping(value="/api/dict_usage_item")
public class DictUsageItemController extends ResultBaseController {
    private  final Logger logger = (Logger) LoggerFactory.getLogger(this.getClass());

    @Autowired
    private DictUsageItemService dictUsageItemService;

    /**
     *通过用法ID过滤该医院查询所有配置信息
     */
    @GetMapping(value="/select_by_usageid.do")
    public ResultUtil selectByUsageID(@CurrentUser DictEmployee dictEmployee,String usageID){
        try {
            return this.success("成功", dictUsageItemService.selectByUsageID(dictEmployee,usageID));
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    /**
     *新增配置
     */
    @RequestMapping(value="/insert.do")
    public ResultUtil insert(@CurrentUser DictEmployee dictEmployee,@RequestBody @Validated(value= Insert.class) DictUsageItemVo dictUsageItemVo){
        try {
            dictUsageItemService.insert(dictEmployee,dictUsageItemVo);
            return this.success("成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
    /**
     *删除配置
     */
    @RequestMapping(value="/delete_byKey.do")
    public ResultUtil delete(@CurrentUser DictEmployee dictEmployee,@RequestBody @Validated(value= Change.class) DictUsageItemVo dictUsageItemVo){
        try {
            dictUsageItemService.delete(dictUsageItemVo);
            return this.success("成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
}
